﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="MonkeyWarranty.Web.Customers.List" %>
<%@ Import Namespace="Resources" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title><%=GlobalStrings.CustomersList %></title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <p>
        <a href="Groups.aspx"><%= GlobalStrings.CustomerGroups %></a>&nbsp;|&nbsp;
        <a href="List.aspx" class="a-selected"><%= GlobalStrings.Customers %></a>
    </p>
    <div class="filtering">
        <label>
            <%=GlobalStrings.Name %>:
            <input type="text" name="name" id="name" /></label>
        <label>
            <%=GlobalStrings.CustomerGroups %>:
            <asp:DropDownList ID="ddlCustomerGroups" runat="server">
            </asp:DropDownList>
        </label>
        <button type="submit" id="LoadRecordsButton"><%=GlobalStrings.LoadRecords %></button>
        <button type="submit" id="ResetButton"><%=GlobalStrings.Reset %></button>
    </div>
    <div id="CustomersTableContainer">
    </div>
    <p><input type="button" value="<%=GlobalStrings.AddNew %>" onclick="javascript:window.location='New.aspx';" /></p>
    <script type="text/javascript">

        $(document).ready(function () {
            //Prepare jtable plugin
            $('#CustomersTableContainer').jtable({
                title: '<%=GlobalStrings.CustomersList %>',
                paging: true,
                pageSize: 15,
                sorting: true,
                defaultSorting: 'Code DESC',
                actions: {
                    listAction: 'List.aspx/CustomerListByFilter',
                    //createAction: 'List.aspx/CreateCustomer',
                    //updateAction: 'List.aspx/UpdateCustomer',
                    deleteAction: 'List.aspx/DeleteCustomer'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    Code: {
                        title: '<%=GlobalStrings.Code %>',
                        defaultValue: 'KH',
                        inputClass: 'validate[required]'
                    },
                    Name: {
                        title: '<%=GlobalStrings.Name %>',
                        width: '23%',
                        inputClass: 'validate[required]'
                    },
                    CustomerGroupId: {
                        title: '<%=GlobalStrings.CustomerGroups %>',
                        width: '12%',
                        options: 'List.aspx/GetCustomerGroupOptions',
                        sorting: false
                    },
                    Phone: { title: '<%=GlobalStrings.Phone %>', sorting: false },
                    Fax: { title: '<%=GlobalStrings.Fax %>', list: false },
                    Email: { title: '<%=GlobalStrings.Email %>', sorting: false },
                    Address: { title: '<%=GlobalStrings.Address %>', sorting: false },
                    Website: { title: '<%=GlobalStrings.Website %>', list: false },
                    TaxCode: { title: '<%=GlobalStrings.TaxCode %>', list: false },
                    BankAccount: { title: '<%=GlobalStrings.BankAccount %>', list: false },
                    BankName: { title: '<%=GlobalStrings.BankName %>', list: false },
                    BankProvince: { title: '<%=GlobalStrings.BankProvince %>', list: false },
                    DirectorName: { title: '<%=GlobalStrings.DirectorName %>', list: false },
                    AccounterName: { title: '<%=GlobalStrings.AccounterName %>', list: false },
                    Description: {
                        title: '<%=GlobalStrings.Description %>',
                        width: '40%',
                        type: 'textarea',
                        list: false,
                        sorting: false
                    },
                    SortOrder: { title: '<%=GlobalStrings.SortOrder %>', defaultValue: '0', inputClass: 'validate[required,custom[integer]]', sorting: false },
                    Hidden: {
                        title: '<%=GlobalStrings.Hidden %>',
                        width: '10%',
                        type: 'checkbox',
                        values: { 'false': 'NO', 'true': 'YES' },
                        defaultValue: 'false',
                        sorting: false
                    },
                    Edit: {
                        title: '',
                        sorting: false,
                        width: '1%',
                        display: function (data) {
                            return '<input class="jtable-command-button jtable-edit-command-button" onclick="javascript:window.location=\'Edit.aspx?id=' + data.record.Id + '\';" />';
                        }
                    }
                },
                //Initialize validation logic when a form is created
                formCreated: function (event, data) {
                    data.form.validationEngine();
                },
                //Validate form when it is being submitted
                formSubmitting: function (event, data) {
                    return data.form.validationEngine('validate');
                },
                //Dispose validation logic when form is closed
                formClosed: function (event, data) {
                    data.form.validationEngine('hide');
                    data.form.validationEngine('detach');
                }
            });

            //Re-load records when user click 'load records' button.
            $('#LoadRecordsButton').click(function (e) {
                e.preventDefault();
                $('#CustomersTableContainer').jtable('load', {
                    name: $('#name').val(),
                    customerGroupId: $('#<% = ddlCustomerGroups.ClientID %>').val()
                });
            });
            
            // Reset button
            $('#ResetButton').click(function (e) {
                e.preventDefault();
                $('#name').val('');
                $('#<% = ddlCustomerGroups.ClientID %>').val('0');
                $('#LoadRecordsButton').click();
            });

            //Load all records when page is first shown
            $('#LoadRecordsButton').click();
        });

    </script>
</asp:Content>
